% TeXdraw toolbox macros, useful for extended TeXdraw commands

% $Id: txdtools.tex,v 1.7 1992/07/07 14:42:13 kabal Rel $

%   Copyright (C) 1991,1992  Peter Kabal

% The routines in this file are provided free of charge without
% warranty of any kind.  Note that the TeXdraw routines are copyrighted.
% They may be distributed freely provided that the recipients also
% acquire the right to distribute them freely.  The notices to this
% effect must be preserved when the files are distributed.

%  Peter Kabal
%  Department of Electrical Engineering
%  McGill University
%  3480 University
%  Montreal, Quebec
%  Canada  H3A 2A7

%  kabal@aldebaran.EE.McGill.CA
\chardef\catamp=\the\catcode`\@
\catcode`\@=11
\def\realadd #1#2#3{\dimen0=#1pt
\dimen2=#2pt
\advance \dimen0 by \dimen2
\edef #3{\expandafter\c@lean\the\dimen0}}
\def\realdiv #1#2#3{\dimen0=#1pt
\t@counta=\dimen0
\dimen0=#2pt
\t@countb=\dimen0
\intdiv \t@counta \t@countb #3}
\def\lenhyp #1#2#3{\t@counta=#1%
\multiply \t@counta by \t@counta
\t@countb=#2%
\multiply \t@countb by \t@countb
\advance \t@counta by \t@countb
\sqrtnum \t@counta #3}
\let\bk=\t@counta
\let\bn=\t@countb
\let\xval=\t@countc
\def\sqrtnum #1#2{\xval=#1%
\bk=\xval
\loop
\bn=\xval
\divide \bn by \bk
\advance \bn by \bk
\advance \bn by 1
\divide \bn by 2
\ifnum \bn < \bk
\bk=\bn
\repeat
#2=\bn}
\def\currentpos #1#2{\t@pixa=\x@pix
\advance \t@pixa by -\x@segoffpix
\pixtocoord \t@pixa #1
\t@pixa=\y@pix
\advance \t@pixa by -\y@segoffpix
\pixtocoord \t@pixa #2}
\def\vectlen (#1 #2)(#3 #4)#5{\getpos (#1 #2)\x@arga\y@arga
\getpos (#3 #4)\x@argb\y@argb
\coordtopix \x@arga \t@pixa
\coordtopix \x@argb \t@pixb
\advance \t@pixb by -\t@pixa
\coordtopix \y@arga \t@pixc
\coordtopix \y@argb \t@pixd
\advance \t@pixd by -\t@pixc
\lenhyp \t@pixb \t@pixd \t@pixc
\pixtocoord \t@pixc #5}
\def\cossin (#1 #2)(#3 #4)#5#6{\getpos (#1 #2)\x@arga\y@arga
\getpos (#3 #4)\x@argb\y@argb
\coordtopix \x@arga \t@pixa
\coordtopix \x@argb \t@pixb
\advance \t@pixb by -\t@pixa
\coordtopix \y@arga \t@pixc
\coordtopix \y@argb \t@pixd
\advance \t@pixd by -\t@pixc
\lenhyp \t@pixb \t@pixd \t@pixc
\intdiv \t@pixb\t@pixc #5%
\intdiv \t@pixd\t@pixc #6}
\catcode`\@=\catamp
